package com.example.demo.utils;

import java.time.LocalDate;

/**
 * CommonUtils
 * Created by jiachun.lu on 2024/08/06.
 */
public class CommonUtils {

    public static Double getTotalProfit(Double totalAmount, Double initialAmount, Double totalInvestAmount) {
        return totalAmount - initialAmount - totalInvestAmount;
    }
    public static Double getTotalProfitPercentage(Double totalAmount, Double initialAmount, Double totalInvestAmount) {
        return getTotalProfit(totalAmount, initialAmount, totalInvestAmount) / (initialAmount+totalInvestAmount) * 100;
    }
    public static Double getAvgYearPercentage(Double totalAmount, Double initialAmount, Double totalInvestAmount, LocalDate startDate, LocalDate endDate) {
        int year = endDate.getYear() - startDate.getYear();
        return (Math.pow(((totalAmount-totalInvestAmount) / (initialAmount)), 1.0/year) - 1)*100;
    }
}
